package yxt.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;

public class Util {
	public static Map<String,Object> jsonp(Map<String,Object> rtn, HttpServletRequest request, HttpServletResponse response) throws IOException {
		String callback = request.getParameter("callback");
		if(callback != null) {
			ObjectMapper mapper = new ObjectMapper();
			response.setCharacterEncoding("UTF-8");
			PrintWriter pw = response.getWriter();
			pw.print(callback+"("+mapper.writeValueAsString(rtn)+")");
			return null;
		}else {
			return rtn;
		}
	}
}
